<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>explain之type | Manor Farm Mysql</title>
    <meta name="generator" content="VuePress 1.7.1">
    <link rel="icon" href="/manor-farm-mysql/pgmanor_mysql.svg">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css">
    <script language="javascript" type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="/manor-farm-mysql/js/MouseClickEffect.js"></script>
    <script language="javascript" type="text/javascript" src="/manor-farm-mysql/js/pgmanor-self.js"></script>
    <meta name="description" content="Mysql学习手册">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/manor-farm-mysql/assets/css/0.styles.7bfce8db.css" as="style"><link rel="preload" href="/manor-farm-mysql/assets/js/app.bbd54b43.js" as="script"><link rel="preload" href="/manor-farm-mysql/assets/js/3.33fa8ee0.js" as="script"><link rel="preload" href="/manor-farm-mysql/assets/js/1.e501e4e7.js" as="script"><link rel="preload" href="/manor-farm-mysql/assets/js/23.2e39bbe5.js" as="script"><link rel="preload" href="/manor-farm-mysql/assets/js/8.73e907b5.js" as="script"><link rel="prefetch" href="/manor-farm-mysql/assets/js/10.31e485b8.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/11.bd87e4cf.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/12.0fe1282f.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/13.f1de335a.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/14.4a84a4ee.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/15.bc190a07.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/16.3f42a3ab.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/17.f1cad67c.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/18.e8063fee.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/19.068739ed.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/20.2b248747.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/21.4fd4cbc1.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/22.2683cc54.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/24.560a4164.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/25.26555323.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/26.8b7e1943.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/27.0f4ac9a1.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/28.f89ec4c0.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/29.71c751c3.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/30.ad576991.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/31.2746a45e.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/32.b62e21d8.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/33.ae9d6c1c.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/34.53969cd0.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/35.3e1a8a01.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/36.eb74300d.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/37.16568451.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/38.9a3bc894.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/39.7aab5a75.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/4.c231685d.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/40.cd44603a.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/41.64d0c11a.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/42.3fb5d657.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/43.d4f19236.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/44.6abd5f31.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/45.eaf7b761.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/46.d891856e.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/5.0292b513.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/6.df2ba939.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/7.3b1acb14.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/9.5220a7da.js">
    <link rel="stylesheet" href="/manor-farm-mysql/assets/css/0.styles.7bfce8db.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-2d5f533b><div data-v-2d5f533b><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-2d5f533b data-v-2d5f533b><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-59a94c5a data-v-2d5f533b data-v-2d5f533b><h3 class="title" style="display:none;" data-v-59a94c5a data-v-59a94c5a>Manor Farm Mysql</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-59a94c5a data-v-59a94c5a><input type="password" value="" data-v-59a94c5a> <span data-v-59a94c5a>已加密!</span> <button data-v-59a94c5a>OK</button></label> <div class="footer" style="display:none;" data-v-59a94c5a data-v-59a94c5a><span data-v-59a94c5a><i class="iconfont reco-eye" data-v-59a94c5a></i> <a target="blank" href="https://pgmanor.gitee.io/blog/" data-v-59a94c5a>密钥</a></span> <span data-v-59a94c5a><i class="iconfont reco-theme" data-v-59a94c5a></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59a94c5a>vuePress-theme-reco</a></span> <span data-v-59a94c5a><i class="iconfont reco-copyright" data-v-59a94c5a></i> <a data-v-59a94c5a><span data-v-59a94c5a>pgmanor</span>
  
<!---->
2021
</a></span></div></div> <div class="hide" data-v-2d5f533b><header class="navbar" data-v-2d5f533b><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/manor-farm-mysql/" class="home-link router-link-active"><img src="/manor-farm-mysql/pgmanor_mysql.svg" alt="Manor Farm Mysql" class="logo"> <span class="site-name">Manor Farm Mysql</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/manor-farm-mysql/zh/guide/" class="nav-link router-link-active"><i class="iconfont reco-api"></i>
  指南
</a></div><div class="nav-item"><a href="/manor-farm-mysql/zh/fix/messageBoard.html" class="nav-link"><i class="iconfont reco-suggestion"></i>
  留言版
</a></div><div class="nav-item"><a href="https://pgmanor.gitee.io/blog/2021/01/10/secret-farm-mysql/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-eye"></i>
  文章密钥
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-qq"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>QQ在线</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://wpa.qq.com/msgrd?v=3&amp;uin=2307546059&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  pgmanor
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li><li class="dropdown-item"><h4>其他方式</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/manor-farm-mysql/zh/fix/contactUs.html" class="nav-link"><i class="iconfont undefined"></i>
  更多
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-other"></i>
      友链
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>博客</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://pgmanor.gitee.io/blog/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  pgmanor
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://blog.csdn.net/u011622109" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-csd"></i>
  csdn
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://www.iworkh.com" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  iworkh
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li><li class="dropdown-item"><h4>Vue</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://cn.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  Vue
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://v1.vuepress.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  VuePress
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://vuepress-theme-reco.recoluan.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  vuepress-theme-reco
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><a href="/manor-farm-mysql/zh/fix/donate.html" class="nav-link"><i class="iconfont reco-Coding"></i>
  捐赠
</a></div><div class="nav-item"><a href="https://gitee.com/pgmanor/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-2d5f533b></div> <aside class="sidebar" data-v-2d5f533b><div class="personal-info-wrapper" data-v-ca798c94 data-v-2d5f533b><img src="/manor-farm-mysql/pgmanor_mysql.svg" alt="author-avatar" class="personal-img" data-v-ca798c94> <h3 class="name" data-v-ca798c94>
    pgmanor
  </h3> <div class="num" data-v-ca798c94><div data-v-ca798c94><h3 data-v-ca798c94>30</h3> <h6 data-v-ca798c94>文章</h6></div> <div data-v-ca798c94><h3 data-v-ca798c94>26</h3> <h6 data-v-ca798c94>标签</h6></div></div> <hr data-v-ca798c94></div> <nav class="nav-links"><div class="nav-item"><a href="/manor-farm-mysql/zh/guide/" class="nav-link router-link-active"><i class="iconfont reco-api"></i>
  指南
</a></div><div class="nav-item"><a href="/manor-farm-mysql/zh/fix/messageBoard.html" class="nav-link"><i class="iconfont reco-suggestion"></i>
  留言版
</a></div><div class="nav-item"><a href="https://pgmanor.gitee.io/blog/2021/01/10/secret-farm-mysql/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-eye"></i>
  文章密钥
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-qq"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>QQ在线</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://wpa.qq.com/msgrd?v=3&amp;uin=2307546059&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  pgmanor
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li><li class="dropdown-item"><h4>其他方式</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/manor-farm-mysql/zh/fix/contactUs.html" class="nav-link"><i class="iconfont undefined"></i>
  更多
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-other"></i>
      友链
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>博客</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://pgmanor.gitee.io/blog/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  pgmanor
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://blog.csdn.net/u011622109" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-csd"></i>
  csdn
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://www.iworkh.com" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  iworkh
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li><li class="dropdown-item"><h4>Vue</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://cn.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  Vue
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://v1.vuepress.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  VuePress
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://vuepress-theme-reco.recoluan.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  vuepress-theme-reco
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><a href="/manor-farm-mysql/zh/fix/donate.html" class="nav-link"><i class="iconfont reco-Coding"></i>
  捐赠
</a></div><div class="nav-item"><a href="https://gitee.com/pgmanor/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav> <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>初入尘世</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/manor-farm-mysql/zh/guide/essentials/e-01-install.html" class="sidebar-link">安装</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-02-ddl-dcl.html" class="sidebar-link">DDL语句</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-03-dml.html" class="sidebar-link">DML语句</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-04-sort.html" class="sidebar-link">sort排序</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-05-group.html" class="sidebar-link">group分组</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-06-union.html" class="sidebar-link">union合并</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-07-join.html" class="sidebar-link">join</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-08-transaction.html" class="sidebar-link">事务</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-09-view.html" class="sidebar-link">视图</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-10-procedure.html" class="sidebar-link">存储过程</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-11-function.html" class="sidebar-link">函数</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-12-index.html" class="sidebar-link">索引</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-13-devops.html" class="sidebar-link">运维</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>千锤百炼</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/manor-farm-mysql/zh/guide/advanced/a-01-introduction.html" class="sidebar-link">本章介绍</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/a-02-prepare-data.html" class="sidebar-link">数据准备</a></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><a href="/manor-farm-mysql/zh/guide/" class="sidebar-heading clickable router-link-active"><span>原理</span> <span class="arrow right"></span></a> <!----></section></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><a href="/manor-farm-mysql/zh/guide/" class="sidebar-heading clickable router-link-active open"><span>优化</span> <span class="arrow down"></span></a> <ul class="sidebar-links sidebar-group-items"><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-01-slow-query.html" class="sidebar-link">慢查询</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-02-mysqldumpslow.html" class="sidebar-link">mysqldumpslow</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-03-explain.html" class="sidebar-link">explain</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-04-explain-select-type.html" class="sidebar-link">explain之select_type</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-05-explain-type.html" aria-current="page" class="active sidebar-link">explain之type</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-06-explain-extra.html" class="sidebar-link">explain之extra</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-07-optimization.html" class="sidebar-link">优化思路和手段</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-08-optimization-join.html" class="sidebar-link">优化之join</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-09-optimization-orderby.html" class="sidebar-link">优化之排序</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-10-optimization-groupby.html" class="sidebar-link">优化之分组</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-11-optimization-struct.html" class="sidebar-link">结构优化</a></li></ul></section></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>百战成神</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-59a94c5a data-v-2d5f533b><h3 class="title" style="display:none;" data-v-59a94c5a data-v-59a94c5a>explain之type</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-59a94c5a data-v-59a94c5a><input type="password" value="" data-v-59a94c5a> <span data-v-59a94c5a>已加密!</span> <button data-v-59a94c5a>OK</button></label> <div class="footer" style="display:none;" data-v-59a94c5a data-v-59a94c5a><span data-v-59a94c5a><i class="iconfont reco-eye" data-v-59a94c5a></i> <a target="blank" href="https://pgmanor.gitee.io/blog/" data-v-59a94c5a>密钥</a></span> <span data-v-59a94c5a><i class="iconfont reco-theme" data-v-59a94c5a></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59a94c5a>vuePress-theme-reco</a></span> <span data-v-59a94c5a><i class="iconfont reco-copyright" data-v-59a94c5a></i> <a data-v-59a94c5a><span data-v-59a94c5a>pgmanor</span>
  
<!---->
2021
</a></span></div></div> <div data-v-2d5f533b><main class="page"><div class="page-title" style="display:none;"><h1 class="title">explain之type</h1> <div data-v-3b7f5bdf><i class="iconfont reco-account" data-v-3b7f5bdf><span data-v-3b7f5bdf>pgmanor</span></i> <i class="iconfont reco-date" data-v-3b7f5bdf><span data-v-3b7f5bdf>2021-01-02</span></i> <i class="iconfont reco-eye" data-v-3b7f5bdf><span id="/manor-farm-mysql/zh/guide/advanced/optimization/a-05-explain-type.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-3b7f5bdf><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="iconfont reco-tag tags" data-v-3b7f5bdf><span class="tag-item" data-v-3b7f5bdf>explain</span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><p>本文主要介绍下explain的type</p> <div id="boxx" data-v-f4ca0dac><div data-v-f4ca0dac><p v-if="true" class="custom-block-title" data-v-f4ca0dac></p> <p v-if="true" data-v-f4ca0dac></p></div></div> <h2 id="_1-type值">1.type值</h2> <p>type显示的是访问类型，是较为重要的一个指标，结果值从好到坏依次是：</p> <blockquote><p>system &gt; const &gt; eq_ref &gt; ref &gt; fulltext &gt; ref_or_null &gt; unique_subquery &gt; index_subquery &gt; range &gt; index_merge &gt; index &gt; ALL</p></blockquote> <p>一般来说，得保证查询至少达到range级别，最好能达到ref</p> <ul><li><strong>system</strong>: 表只有一条记录(等于系统表),这是const类型的特例，平时业务中不会出现，且只能用于myisam和memory表。如果是Innodb引擎表，type列在这个情况通常都是all或者index</li> <li><strong>const</strong>: 通过索引一次查到数据，该类型主要用于比较primary key 或者unique 索引，因为只匹配一行数据，所以很快;如果将主键置于WHERE语句后面，Mysql就能将该查询转换为一个常量。</li> <li><strong>eq_ref</strong>: 多表关联查询时，被驱动表是<code>主键</code>或<code>唯一索引</code>扫描，对于每个索引键，表中<code>只有一条记录</code>与之匹配，且为非空not null。</li> <li><strong>ref</strong>: 不像eq_ref那样要求连接顺序，也没有主键和唯一索引的要求，只要使用相等条件检索时就可能出现，常见与辅助索引的等值查找。或者多列主键、唯一索引中，使用第一个列之外的列作为等值查找也会出现，总之，返回数据不唯一的等值查找就可能出现。</li> <li><strong>fulltext</strong>：全文索引检索，要注意，全文索引的优先级很高，若全文索引和普通索引同时存在时，mysql不管代价，优先选择使用全文索引</li> <li><strong>ref_or_null</strong>：与ref方法类似，只是增加了null值的比较。实际用的不多。</li> <li><strong>unique_subquery</strong>：用于where中的in形式子查询，子查询返回不重复值唯一值</li> <li><strong>index_subquery</strong>：用于in形式子查询使用到了辅助索引或者in常数列表，子查询可能返回重复值，可以使用索引将子查询去重。</li> <li><strong>range</strong>：只检索给定范围的行，使用一个索引来选着行。key列显示使用了哪个索引。一般在你的WHERE 语句中出现<code>between ,&lt; ,&gt; , in</code> 等查询，这种给定范围扫描比全表扫描要好。因为他只需要开始于索引的某一点，而结束于另一点，不用扫描全部索引。</li> <li><strong>index_merge</strong>: 两个以上所有，然后取交集或者并集。比如and、or条件使用了不同条件。</li> <li><strong>index</strong>：扫描遍历索引树(扫描全表的索引，从索引中获取数据)。常见于使用索引列就可以处理不需要读取数据文件的查询、可以使用索引排序或者分组的查询。</li> <li><strong>ALL</strong>: 全表扫描,然后再在server层进行过滤返回符合要求的记录。从磁盘中获取数据 百万级别的数据ALL类型的数据尽量优化。</li></ul> <blockquote><p><a href="https://www.cnblogs.com/nxld/p/6443547.html" target="_blank" rel="noopener noreferrer">参照--mysql explain执行计划详解<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></blockquote> <h2 id="_2-system">2.system</h2> <p><strong>system</strong>: 表只有一条记录(等于系统表),这是const类型的特例，平时业务中不会出现，在myisam引擎和memory内存的表中。</p> <p>必须具备以下条件才能满足type为system</p> <ul><li>MyISAM引擎</li> <li>只有一条数据</li></ul> <p><strong>创建表</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>sys_info<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sys_name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token keyword">COLLATE</span> utf8mb4_general_ci <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统名称'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sys_version<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token keyword">COLLATE</span> utf8mb4_general_ci <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统版本'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sys_push_time<span class="token punctuation">`</span> <span class="token keyword">datetime</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'发布时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sys_company_name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token keyword">COLLATE</span> utf8mb4_general_ci <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统公司'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sys_company_mail<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token keyword">COLLATE</span> utf8mb4_general_ci <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统公司邮箱'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sys_company_phone<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">COLLATE</span> utf8mb4_general_ci <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统公司电话'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sys_company_website<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">COLLATE</span> utf8mb4_general_ci <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统公司网站'</span><span class="token punctuation">,</span>
   <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span>MyISAM <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COLLATE</span><span class="token operator">=</span>utf8mb4_general_ci<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p><strong>插入数据sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> manor_farm_mysql<span class="token punctuation">.</span>sys_info <span class="token punctuation">(</span>sys_name<span class="token punctuation">,</span>sys_version<span class="token punctuation">,</span>sys_push_time<span class="token punctuation">,</span>sys_company_name<span class="token punctuation">,</span>sys_company_mail<span class="token punctuation">,</span>sys_company_phone<span class="token punctuation">,</span>sys_company_website<span class="token punctuation">)</span> <span class="token keyword">VALUES</span> 
<span class="token punctuation">(</span><span class="token string">'manor-farm-mysql'</span><span class="token punctuation">,</span><span class="token string">'1.0'</span><span class="token punctuation">,</span><span class="token boolean">NULL</span><span class="token punctuation">,</span><span class="token string">'pgmanor'</span><span class="token punctuation">,</span><span class="token string">'pgmanor@qq.com'</span><span class="token punctuation">,</span><span class="token string">'88888888'</span><span class="token punctuation">,</span><span class="token string">'https://pgmanor.gitee.io/manor-farm-mysql/'</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>查询数据sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> sys_info<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>::: error 注意
MyISAM引擎表中只一条数据，如果超过一条type也不会为system
:::</p> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>sys_info</td> <td></td> <td>system</td> <td></td> <td></td> <td></td> <td></td> <td>1</td> <td>100.0</td> <td></td></tr></tbody></table> <h2 id="_3-const">3.const</h2> <p><strong>const</strong>: 查询条件使用了唯一索引(主键索引也可以)，返回记录有且为一条</p> <p>通过索引一次查到数据，该类型主要用于比较primary key 或者unique 索引，因为只匹配一行数据，所以很快;如果将主键置于WHERE语句后面，Mysql就能将该查询转换为一个常量。</p> <p>必须具备以下条件才能满足type为const</p> <ul><li>索引为唯一索引(primary key或unique key都行)</li> <li>一条结果数据</li></ul> <h3 id="_3-1-primary-key">3-1.primary key</h3> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> <span class="token keyword">select</span> store_id <span class="token keyword">from</span> store <span class="token keyword">where</span> store_id <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>store</td> <td></td> <td>const</td> <td>PRIMARY</td> <td>PRIMARY</td> <td>1</td> <td>const</td> <td>1</td> <td>100.0</td> <td>Using index</td></tr></tbody></table> <h3 id="_3-2-unique-key">3-2.unique key</h3> <p>使用<code>sakila</code>的<code>store</code>表的<code>manager_staff_id</code>为条件来演示，因为<code>manager_staff_id</code>为<code>UNIQUE KEY</code>(唯一索引)</p> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> <span class="token keyword">select</span> store_id <span class="token keyword">from</span> store <span class="token keyword">where</span> manager_staff_id <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>store</td> <td></td> <td>const</td> <td>idx_unique_manager</td> <td>idx_unique_manager</td> <td>1</td> <td>const</td> <td>1</td> <td>100.0</td> <td>Using index</td></tr></tbody></table> <h3 id="_3-3-非一条结果">3-3.非一条结果</h3> <p>我们来看下是primary key，但是结果为多条。也不是const</p> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> <span class="token keyword">select</span> store_id <span class="token keyword">from</span> store <span class="token keyword">where</span> store_id <span class="token operator">in</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><blockquote><p>查询1和2两条结果，虽然使用主键、唯一索引，但是也不会是const</p></blockquote> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>store</td> <td></td> <td>index</td> <td>PRIMARY</td> <td>idx_unique_manager</td> <td>1</td> <td></td> <td>2</td> <td>100.0</td> <td>Using where; Using index</td></tr></tbody></table> <h3 id="_3-4-普通索引">3-4.普通索引</h3> <p>使用<code>sakila</code>的<code>store</code>表的<code>address_id</code>为条件来演示，因为<code>address_id</code>为<code>KEY</code>(普通索引)</p> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> <span class="token keyword">select</span> store_id <span class="token keyword">from</span> store <span class="token keyword">where</span> address_id <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>store</td> <td></td> <td>ref</td> <td>idx_fk_address_id</td> <td>idx_fk_address_id</td> <td>2</td> <td>const</td> <td>1</td> <td>100.0</td> <td>Using index</td></tr></tbody></table> <h2 id="_4-eq-ref">4.eq_ref</h2> <p><strong>eq_ref</strong>: 多表关联查询时，<strong>被驱动表</strong>是<code>主键</code>或<code>唯一索引</code>扫描，对应表中<code>只有一条记录</code>与之匹配，且为非空not null。</p> <p>必须具备以下条件才能满足type为<code>eq_ref</code></p> <ul><li>多表查询</li> <li>被驱动表是<code>主键</code>或<code>唯一索引</code>扫描</li> <li>关联关系必须要满足：驱动表1条数据，对应被驱动表<code>有且只有一条数据</code>，且为非空</li></ul> <h3 id="_4-1-正常示例">4-1.正常示例</h3> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span>
	store<span class="token punctuation">.</span>store_id<span class="token punctuation">,</span> address<span class="token punctuation">.</span>address 
<span class="token keyword">from</span>
	store
<span class="token keyword">left</span> <span class="token keyword">join</span> address <span class="token keyword">on</span>
	store<span class="token punctuation">.</span>address_id <span class="token operator">=</span> address<span class="token punctuation">.</span>address_id
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><blockquote><p>store为驱动表，address为非驱动表。<code>address.address_id</code>为address表中的primary key，所以返回只有一条，且为非空</p></blockquote> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>store</td> <td></td> <td>index</td> <td></td> <td>idx_fk_address_id</td> <td>2</td> <td></td> <td>2</td> <td>100.0</td> <td>Using index</td></tr> <tr><td>1</td> <td>SIMPLE</td> <td>address</td> <td></td> <td>eq_ref</td> <td>PRIMARY</td> <td>PRIMARY</td> <td>2</td> <td>sakila.store.address_id</td> <td>1</td> <td>100.0</td> <td></td></tr></tbody></table> <blockquote><p>先从store表中查出，然后每条去address中查询，对于address有且只有一条。</p></blockquote> <h3 id="_4-2-被驱动表多条">4-2.被驱动表多条</h3> <p>关联关系不满足有且有一条时，被驱动表中有多条时，则type不为eq_ref，而是后面将介绍的ref</p> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> 
    film<span class="token punctuation">.</span>title<span class="token punctuation">,</span> inventory<span class="token punctuation">.</span>store_id
<span class="token keyword">from</span> 
    film 
<span class="token keyword">left</span> <span class="token keyword">join</span> inventory <span class="token keyword">on</span> 
    film<span class="token punctuation">.</span>film_id <span class="token operator">=</span> inventory<span class="token punctuation">.</span>film_id 
<span class="token keyword">where</span>
    film<span class="token punctuation">.</span>film_id <span class="token operator">=</span> <span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>const</td> <td>PRIMARY</td> <td>PRIMARY</td> <td>2</td> <td>const</td> <td>1</td> <td>100.0</td> <td></td></tr> <tr><td>1</td> <td>SIMPLE</td> <td>inventory</td> <td></td> <td>ref</td> <td>idx_fk_film_id</td> <td>idx_fk_film_id</td> <td>2</td> <td>const</td> <td>8</td> <td>100.0</td> <td></td></tr></tbody></table> <h2 id="_5-ref">5.ref</h2> <p><strong>ref</strong>:非唯一索引扫描，返回匹配某个单独值得所有行，本质上是一种索引访问，它返回所有匹配某个单独值的行，就是说它可能会找到多条符合条件的数据。</p> <blockquote><p>则ref出现，不像<code>eq_ref</code>，需要多个表，唯一索引，返回一条的限制，只要是索引查询就可能会出现</p></blockquote> <p>必须具备以下条件才能满足type为ref</p> <ul><li>条件为索引
<ul><li>唯一索引，返回单条和多条。(如果多条关联查询、唯一返回单条，可能会出现上面介绍的<code>eq_ref</code>)</li> <li>普通索引，返回单条和多条</li></ul></li></ul> <h3 id="_5-1-单表查询">5-1.单表查询</h3> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film_actor
<span class="token keyword">where</span> film_actor<span class="token punctuation">.</span>actor_id <span class="token operator">=</span> <span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><blockquote><p>单表查询，返回了多条数据</p></blockquote> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film_actor</td> <td></td> <td>ref</td> <td>PRIMARY</td> <td>PRIMARY</td> <td>2</td> <td>const</td> <td>19</td> <td>100.0</td> <td></td></tr></tbody></table> <h3 id="_5-2-关联查询">5-2.关联查询</h3> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> 
    film<span class="token punctuation">.</span>title<span class="token punctuation">,</span> inventory<span class="token punctuation">.</span>store_id
<span class="token keyword">from</span> 
    film 
<span class="token keyword">left</span> <span class="token keyword">join</span> inventory <span class="token keyword">on</span> 
    film<span class="token punctuation">.</span>film_id <span class="token operator">=</span> inventory<span class="token punctuation">.</span>film_id 
<span class="token keyword">where</span>
    film<span class="token punctuation">.</span>film_id <span class="token operator">=</span> <span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><blockquote><p>返回了多条数据，不满足<code>eq_ref</code>，所以为ref</p></blockquote> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>const</td> <td>PRIMARY</td> <td>PRIMARY</td> <td>2</td> <td>const</td> <td>1</td> <td>100.0</td> <td></td></tr> <tr><td>1</td> <td>SIMPLE</td> <td>inventory</td> <td></td> <td>ref</td> <td>idx_fk_film_id</td> <td>idx_fk_film_id</td> <td>2</td> <td>const</td> <td>8</td> <td>100.0</td> <td></td></tr></tbody></table> <blockquote><p>ref等级，也是我们开始时候，要追求的指标。</p></blockquote> <h2 id="_6-fulltext">6.fulltext</h2> <p><strong>fulltext</strong>: 全文检索，全文检索优先级比普通索引高。即若全文索引和普通索引同时存在时，mysql不管代价，优先选择使用全文索引</p> <p>必须具备以下条件才能满足type为fulltext</p> <ul><li>条件索引为全文索引</li></ul> <p>以<code>film_text</code>为例如，因为它使用了全文索引，其表结构为</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> film_text <span class="token punctuation">(</span>
  film_id <span class="token keyword">SMALLINT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  title <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  description <span class="token keyword">TEXT</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span>  <span class="token punctuation">(</span>film_id<span class="token punctuation">)</span><span class="token punctuation">,</span>
  FULLTEXT <span class="token keyword">KEY</span> idx_title_description <span class="token punctuation">(</span>title<span class="token punctuation">,</span>description<span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><blockquote><p><code>idx_title_description</code>为<code>FULLTEXT KEY</code></p></blockquote> <p>如何给一个表字段加全文索引？(语法格式如下)</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">ALTER</span> <span class="token keyword">table</span> 表名 <span class="token keyword">ADD</span> FULLTEXT <span class="token keyword">INDEX</span> 索引名称<span class="token punctuation">(</span>列字段<span class="token number">1</span><span class="token punctuation">,</span>列字段<span class="token number">2.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film_text
<span class="token keyword">where</span> 
	<span class="token keyword">match</span><span class="token punctuation">(</span>title<span class="token punctuation">,</span>description<span class="token punctuation">)</span> against<span class="token punctuation">(</span><span class="token string">'%Girl BOY%'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><blockquote><p>match和against语法来查询，多个关键字，使用空格分隔</p></blockquote> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film_text</td> <td></td> <td>fulltext</td> <td>idx_title_description</td> <td>idx_title_description</td> <td>0</td> <td>const</td> <td>1</td> <td>100.0</td> <td>Using where; Ft_hints: sorted</td></tr></tbody></table> <blockquote><p>要满足<code>fulltext</code>字段是全文索引才行</p></blockquote> <h2 id="_7-ref-or-null">7.ref_or_null</h2> <ul><li><strong>ref_or_null</strong>：与ref方法类似，只是增加了null值的比较。实际用的不多。</li></ul> <p>必须具备以下条件才能满足type为ref_or_null</p> <ul><li>条件字段为索引</li></ul> <p><strong>表结构</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>dept<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>deptno<span class="token punctuation">`</span> <span class="token keyword">int</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'部门编号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>dname<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'部门名称'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>loc<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'部门所在位置'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>deptno<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> <span class="token punctuation">`</span>index_name<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>dname<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token operator">=</span><span class="token number">4</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COLLATE</span><span class="token operator">=</span>utf8mb4_0900_ai_ci <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'部门表'</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><blockquote><p>然后自己插入几条数据，测试下</p></blockquote> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> dept 
<span class="token keyword">where</span> dname <span class="token operator">=</span><span class="token string">'HR'</span> <span class="token operator">or</span> dname <span class="token operator">is</span> <span class="token boolean">null</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>dept</td> <td></td> <td>ref_or_null</td> <td>index_name</td> <td>index_name</td> <td>63</td> <td>const</td> <td>2</td> <td>100.0</td> <td>Using index condition</td></tr></tbody></table> <blockquote><p>条件中需要有<code>is null</code></p></blockquote> <h2 id="_8-unique-subquery">8.unique_subquery</h2> <p><strong>unique_subquery</strong>：用于where中的in形式子查询，子查询返回不重复值唯一值</p> <ul><li><a href="https://dev.mysql.com/doc/refman/8.0/en/explain-output.html#jointype_eq_ref" target="_blank" rel="noopener noreferrer">官网解释<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">value</span> <span class="token operator">IN</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> primary_key <span class="token keyword">FROM</span> single_table <span class="token keyword">WHERE</span> some_expr<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><blockquote><p>根据官网的示例，演示如下，没有试出结果，type为<code>ref</code></p></blockquote> <p><strong>示例</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> 
	film<span class="token punctuation">.</span>title
<span class="token keyword">from</span> film
<span class="token keyword">where</span>
	film_id <span class="token operator">in</span> <span class="token punctuation">(</span><span class="token keyword">select</span> film_id <span class="token keyword">from</span> film_category <span class="token keyword">where</span> film_category<span class="token punctuation">.</span>category_id <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film_category</td> <td></td> <td>ref</td> <td>PRIMARY,fk_film_category_category</td> <td>fk_film_category_category</td> <td>1</td> <td>const</td> <td>64</td> <td>100.0</td> <td>Using index</td></tr> <tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>eq_ref</td> <td>PRIMARY</td> <td>PRIMARY</td> <td>2</td> <td>sakila.film_category.film_id</td> <td>1</td> <td>100.0</td> <td></td></tr></tbody></table> <h2 id="_9-range">9.range</h2> <p><strong>range</strong>：只检索给定范围的行，使用一个索引来选着行。key列显示使用了哪个索引。</p> <p>一般在WHERE 语句中出现<code>between ,&lt; ,&gt; , in</code> 等查询，这种给定范围扫描比全表扫描要好。因为他只需要开始于索引的某一点，而结束于另一点，不用扫描全部索引。</p> <p>必须具备以下条件才能满足type为range</p> <ul><li>条件字段为索引</li> <li>条件为范围查询</li></ul> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span> film_id <span class="token operator">in</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>range</td> <td>PRIMARY</td> <td>PRIMARY</td> <td>2</td> <td></td> <td>2</td> <td>100.0</td> <td>Using where</td></tr></tbody></table> <blockquote><p>mysql的in条件虽然没有限制个数。但是对于sql整体的长度是有限制的。8.0版本默认是64M(各个版本略有不同)。</p> <p>可以去官网<a href="https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_max_allowed_packet" target="_blank" rel="noopener noreferrer">mysql系统变量<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>
，然后搜索关键字<code>max-allowed-packet</code>可以找到其默认值</p></blockquote> <h2 id="_10-index-merge">10.index_merge</h2> <p><strong>index_merge</strong>: 两个以上所有，然后取交集或者并集。比如and、or条件使用了不同条件。</p> <p>必须具备以下条件才能满足type为index_merge</p> <ul><li>多个or和and条件</li> <li>or或者and的条件字段为都为索引</li></ul> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span> 
film_id <span class="token operator">=</span><span class="token number">10</span> 
<span class="token operator">or</span> title <span class="token operator">=</span><span class="token string">'ACADEMY DINOSAUR'</span> 
<span class="token operator">or</span> original_language_id <span class="token operator">=</span><span class="token number">2</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>由于结果比较长，所以使用列方式打印出来了。</p> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>Name</th> <th>Value</th></tr></thead> <tbody><tr><td>id</td> <td>1</td></tr> <tr><td>select_type</td> <td>SIMPLE</td></tr> <tr><td>table</td> <td>film</td></tr> <tr><td>partitions</td> <td></td></tr> <tr><td>type</td> <td>index_merge</td></tr> <tr><td>possible_keys</td> <td>PRIMARY,idx_title,idx_fk_original_language_id</td></tr> <tr><td>key</td> <td>PRIMARY,idx_title,idx_fk_original_language_id</td></tr> <tr><td>key_len</td> <td>2,514,2</td></tr> <tr><td>ref</td> <td></td></tr> <tr><td>rows</td> <td>3</td></tr> <tr><td>filtered</td> <td>100.0</td></tr> <tr><td>Extra</td> <td>Using union(PRIMARY,idx_title,idx_fk_original_language_id); Using where</td></tr></tbody></table> <h2 id="_10-index">10.index</h2> <p><strong>index</strong>: 扫描遍历索引树(扫描全表的索引，从索引中获取数据)。常见于使用索引列就可以处理不需要读取数据文件的查询、可以使用索引排序或者分组的查询。</p> <p>必须具备以下条件才能满足type为index</p> <ul><li>所需要的值就在索引中，不需要去回表查询了</li> <li>扫描了全表</li></ul> <p>我们先来看下film的建表语句</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> film <span class="token punctuation">(</span>
  film_id <span class="token keyword">SMALLINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
  title <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  description <span class="token keyword">TEXT</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  release_year <span class="token keyword">YEAR</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  language_id <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  original_language_id <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  rental_duration <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">3</span><span class="token punctuation">,</span>
  rental_rate <span class="token keyword">DECIMAL</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">4.99</span><span class="token punctuation">,</span>
  length <span class="token keyword">SMALLINT</span> <span class="token keyword">UNSIGNED</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  replacement_cost <span class="token keyword">DECIMAL</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">19.99</span><span class="token punctuation">,</span>
  rating <span class="token keyword">ENUM</span><span class="token punctuation">(</span><span class="token string">'G'</span><span class="token punctuation">,</span><span class="token string">'PG'</span><span class="token punctuation">,</span><span class="token string">'PG-13'</span><span class="token punctuation">,</span><span class="token string">'R'</span><span class="token punctuation">,</span><span class="token string">'NC-17'</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token string">'G'</span><span class="token punctuation">,</span>
  special_features <span class="token keyword">SET</span><span class="token punctuation">(</span><span class="token string">'Trailers'</span><span class="token punctuation">,</span><span class="token string">'Commentaries'</span><span class="token punctuation">,</span><span class="token string">'Deleted Scenes'</span><span class="token punctuation">,</span><span class="token string">'Behind the Scenes'</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  last_update <span class="token keyword">TIMESTAMP</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span>  <span class="token punctuation">(</span>film_id<span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> idx_title <span class="token punctuation">(</span>title<span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> idx_fk_language_id <span class="token punctuation">(</span>language_id<span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> idx_fk_original_language_id <span class="token punctuation">(</span>original_language_id<span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">CONSTRAINT</span> fk_film_language <span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span>language_id<span class="token punctuation">)</span> <span class="token keyword">REFERENCES</span> <span class="token keyword">language</span> <span class="token punctuation">(</span>language_id<span class="token punctuation">)</span> <span class="token keyword">ON</span> <span class="token keyword">DELETE</span> <span class="token keyword">RESTRICT</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CASCADE</span><span class="token punctuation">,</span>
  <span class="token keyword">CONSTRAINT</span> fk_film_language_original <span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span>original_language_id<span class="token punctuation">)</span> <span class="token keyword">REFERENCES</span> <span class="token keyword">language</span> <span class="token punctuation">(</span>language_id<span class="token punctuation">)</span> <span class="token keyword">ON</span> <span class="token keyword">DELETE</span> <span class="token keyword">RESTRICT</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CASCADE</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><blockquote><p>有四个索引，我们来查询有哪些电影名称(title)</p></blockquote> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> title <span class="token keyword">from</span> film 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>index</td> <td></td> <td>idx_title</td> <td>514</td> <td></td> <td>1000</td> <td>100.0</td> <td>Using index</td></tr></tbody></table> <blockquote><p>没有where条件，索引扫描了全表。而查询的字段是<code>title</code>,刚好在<code>idx_title</code>的索引中，所以满足了type为<code>index</code>的条件。</p></blockquote> <h2 id="_11-all">11.all</h2> <p><strong>all</strong>: 全表扫描,然后再在server层进行过滤返回符合要求的记录。从磁盘中获取数据 百万级别的数据ALL类型的数据尽量优化。</p> <blockquote><p>这个性能是最差的，数据量大后了，如果不想系统三天两头就挂了，就尽快的优化吧。</p></blockquote> <h3 id="_11-1-没有索引">11-1.没有索引</h3> <p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span> release_year<span class="token operator">=</span><span class="token number">2006</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ALL</td> <td></td> <td></td> <td></td> <td></td> <td>1000</td> <td>10.0</td> <td>Using where</td></tr></tbody></table> <blockquote><p><code>release_year</code>不是索引字段，需要全表扫描</p></blockquote> <h3 id="_11-2-重复索引">11-2.重复索引</h3> <p>我们先来对比下下面两个sql的执行计划结果</p> <p><strong>A: 查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span> language_id <span class="token operator">=</span> <span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><blockquote><p>有where条件，，language_id是普通索引，不是全表扫描，查询字段是所有字段，language_id记录很多。
mysql认为全表all扫描处理的效率比通过<code>language_id</code>找到对于的主键索引后，再通过主键索引找到字段的效率高。所以使用了all</p></blockquote> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ALL</td> <td>idx_fk_language_id</td> <td></td> <td></td> <td></td> <td>1000</td> <td>100.0</td> <td>Using where</td></tr></tbody></table> <p><strong>B: 查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> language_id <span class="token keyword">from</span> film 
<span class="token keyword">where</span> language_id <span class="token operator">=</span> <span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><blockquote><p>有where条件，language_id是普通索引，不是全表扫描。会有多条数据返回，所以是ref，而不是const。</p></blockquote> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ref</td> <td>idx_fk_language_id</td> <td>idx_fk_language_id</td> <td>1</td> <td>const</td> <td>1000</td> <td>100.0</td> <td>Using index</td></tr></tbody></table> <p><strong>C: 查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span> title <span class="token operator">=</span> <span class="token string">'ACADEMY DINOSAUR'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><blockquote><p>这个A的sql类似，这是条件不一样，但是条件的字段都有普通索引的。但是结果却不是all的，而是ref的。</p> <p>因为<code>language_id</code>的重复数据太多了。<code>title</code>值比较分散，基本没有重复的。</p></blockquote> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ref</td> <td>idx_title</td> <td>idx_title</td> <td>514</td> <td>const</td> <td>1</td> <td>100.0</td> <td></td></tr></tbody></table> <p>A和B两个sql，两个sql的where条件是一样，但是他们的查询出来的字段是不一样的，其执行计划的结果<code>type</code>也是不一样的。</p> <p>但是C的sql，也查出了所有字段，type却还是<code>ref</code>？为什么了？ (原因上面已经介绍过了)</p></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2021-1-10 10:48:19 PM</span></div></footer> <!----> <!----> <!----></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div><!----><!----><APlayer audio="" fixed="true" mini="true" theme="#f9bcdd" loop="loop" order="random" preload="auto" volume="0.1" mutex="true" lrc-type="0" list-folded="true" list-max-height="250" storage-name="vuepress-plugin-meting" id="aplayer-fixed"></APlayer></div></div>
    <script src="/manor-farm-mysql/assets/js/app.bbd54b43.js" defer></script><script src="/manor-farm-mysql/assets/js/3.33fa8ee0.js" defer></script><script src="/manor-farm-mysql/assets/js/1.e501e4e7.js" defer></script><script src="/manor-farm-mysql/assets/js/23.2e39bbe5.js" defer></script><script src="/manor-farm-mysql/assets/js/8.73e907b5.js" defer></script>
  </body>
</html>
